<?php
/*
 * @version :  2013-4-22
 * @project :  account-system
 * @Author  :  Allen
 * @e-mail  :  shulei@maszy.cn
 */
  require_once (dirname(__FILE__)."/../config/config.php");
 $content = getXml();
 outPutXml($content);
function getXml(){
	$content = "";
	if(isset($_REQUEST['mac'])){
		$sql1="select * from zy_equipment  where MacAddress='".$_REQUEST['mac']."'";
		$rss = mysql_query($sql1);
		$rows = mysql_fetch_array($rss);
		
		$sqlpackage = "select * from zy_user_service where user_id='".$rows['updater']."' and service_id = 14";
		$rsult = mysql_query($sqlpackage);
		//$rowsrs = mysql_fetch_array($rsult);
		$i=0;
		//获取用户的订购列表.
		while($rowsrs = mysql_fetch_array($rsult)){
			$sql="select * from zy_iptv_package_details where package_id=".$rowsrs['package_id'];
			$rs = mysql_query($sql);
			
			while ($result=mysql_fetch_array($rs)) {
				$arr[$i]=$result['channel_id'];
				$i++;
			}
		}
		

		$all_channels_sql="SELECT a.* FROM `zy_tvchannel` AS a ,`zy_tvshow` AS b WHERE a.tv_id =b.tv_id ORDER BY b.sort ASC ,a.sort ASC";
		$all_channels_rs=mysql_query($all_channels_sql);
		while($row = mysql_fetch_array($all_channels_rs)){
				$content.= "<result>\n";
				$content.= "<channelid> ".$row['channel_id']." </channelid>\n";
				$content.= "<channellistid > ".$row['tv_id']." </channellistid >\n";
				$content.= "<description>".$row['channel_name']."</description>\n";
				$content.= "<url>".$row['channel_url']."</url>\n";
				//判断该节目信息是否包含在用户订购的套餐列表里.
				if(in_array($row['channel_id'],$arr)){
		   		 	$content.= "<available>1</available>\n";
				}else{
				    $content.= "<available>0</available>\n";
				}
				$content.= "</result>\n";
		}
	}
	return $content;
}

function outPutXml($content) {
	header("Content-type:text/xml");
	echo "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n";
	echo "<netcuberesult>\n";
	echo $content;
	echo "</netcuberesult>";
	die();
}
